<{*积分商城-兑换活动详情*}>
<{include file="top.html"}>
</head>
<body>
<div class="xy-panel">
    <div class="xy-panel-top">
        <div class="xy-titlebar">
            <div class="xy-titlebar-left">
                <a class="insertBefore_left_arrow_gray" href="javascript:void(0);"></a>
            </div>
            <div class="xy-titlebar-title">商品详情</div>
            <div class="xy-titlebar-right"></div>
        </div>
    </div>
    <div class="xy-panel-content" style="bottom:0;">
        <div class="xy-row vDirectionRow">
            <div class="jfdh_box">
                <div class="jfdh_topic"><{$obj.titleInner}><{* <span class="dj jk_dj">Lv.<{$obj.userLevelRequire}></span> *}></div>
                <div class="jfdh_img"><img src="<{$preUploadUrl}><{$obj.cover}>" /></div>

                    <{if $obj.stock==0 || $obj.overdue == true}>
                        <div class="jkqsj_box" >活动已经结束</div>
                    <{else}>
                         <div class="jkqsj_box" id="exchange-time" data-time="<{$obj.rest_time}>">距离开抢</div>
                    <{/if}>

                <div id="fixed" class="exchange clear">
                    <div class="new">
                        <div class="box"></div>

                            <{if $obj.showStock == $POINTMALL_NO_STACK}>
                                <div class="hd_btn yjs_2">已售完</div>
                            <{else if $obj.overdue == true}>
                                <div class="hd_btn yjs_2">活动已结束</div>
                            <{else}>
                                <div class="hd_btn yjs_2 cd-popup-trigger" data-time="<{$obj.rest_time}>" data-type = "<{$obj.deliveryType}>" id="exchange-btn">
                                    <{if $obj.point eq 0 and $obj.nowPrice gt 0}>
                                    购买
                                    <{else}>
                                    兑换
                                    <{/if}>
                                </div>
                            <{/if}>


                        <{*<div class="jfdh_btn_2 qqd_txw cd-popup-trigger">提醒我</div>*}>
                        <!--如果quota为0 则表示无限购-->
                        <{if $obj.quota == -1}>
                        <div class="num xzdh">
                            无限购
                        </div>
                        <{else}>
                        <div class="num xzdh">限兑 <span class="rmb-num" id="quota"><{$obj.quota}></span>件</div>
                        <{/if}>
                    </div>
                    <div class="price">
                        <span class="rmb-num">
                             <{* 显示积分与价格 *}>
                            <{if $obj.point gt 0 and $obj.nowPrice eq 0}>
                                <{$obj.point}>积分
                            <{elseif  $obj.point eq 0 and $obj.nowPrice gt 0 }>
                                <{$obj.nowPrice}>元
                            <{elseif  $obj.point gt 0 and $obj.nowPrice gt 0 }>
                                <{$obj.point}>积分 +<{$obj.nowPrice}>元
                            <{/if}>
                            <br><span>￥<{$obj.originalPrice}></span>
                        </span>
                    </div>
                    <{if $obj.stock == $POINTMALL_NO_LIMIT}>
                    <div class="num">
                        无限制数量
                    </div>
                    <{else}>
                    <div class="num">
                        已售 <span id="stock" class="rmb-num"><{$obj.buyNum}></span>件
                    </div>
                    <{/if}>
                </div>

            </div>



            <div class="stsm_box">
                <div class="sysm_topic">使用说明</div>
                <{$obj.content}>
            </div>
        </div>
    </div>
</div>

<div class="hyjf_box">
    <a href="<{$POINT_RULE_URL}>" style="color: #fff;"><div class="jfgz">积分规则</div></a>
    <div class="hy_box"><{if $userinfo}>Lv.<{$userinfo.levelHtml}><{else}><a style="color:white" href="<{U('User/login')}>">请登陆</a><{/if}></div>
    <div class="price">积分 <span class="rmb-num" id="nowPoint"><{$userinfo.point|default:0}></span>
    </div>
</div>

<!--弹出框—积分兑换-->
<div class="hint-box" id="hint-send">
    <div class="hint hdbm_box">
		<a class="close" href="javascript:void(0)" onclick="$('#hint-send').hide()"></a>
        <div class="topic" id="send-title">恭喜您抢到了</div>
        <div class="title">请填写信息，工作人员将尽快为您发货。<br>信息不完整视为放弃哦~</div>
        <input type="hidden" id="send-id" value="">
        <div class="hdbm_item" style="margin-top:0;">
            姓&nbsp;&nbsp;名
            <input type="text" id="send-name" value="<{$userinfo.realName}>"/>
        </div>
        <div class="hdbm_item">
            联系电话
            <input type="text"  id="send-phone" value="<{$userinfo.bindPhone}>"/>
        </div>
        <div class="hdbm_item jfdh_form">
            详细地址
            <textarea id="send-address"><{$userinfo.address}></textarea>
        </div>
            <button type="button" id="send-btn-exchange" class="button">提交信息</button>

    </div>
</div>

<!--弹出框—积分兑换-->
    <div class="hint-box" id="exchangeConfirm" >
        <div class="hint exchange_box">
            <h3 class="topic">确认兑换</h3>
            <dl class="list">您当前有<{$userinfo.point}>积分，<br>确认兑换将扣除<{$obj.point}>积分确认</dl>
            <div class="btn_box">
                <button type="button" id="confirmCancel" class="button">取 消</button>
                <button type="button" id="confirmOk" class="button">确 认</button>
            </div>
        </div>
    </div>


<!--弹出框 mustFollow-->
<div id="mustFollow" class="hint-box" style="display:none;">
    <div class="hint nofollow_box">
        <div class="topic title">请关注丸子妈妈！</div>
        <{if !$userinfo.WX_openid}>
        <dl class="con"><img src="<{$preStaticUrl}>Wap/images/<{$qrcode_path}>" /></dl>
        <{/if}>
        <dl class="list text">关注丸子妈妈，才可享受全部福利唷</dl>
        <dl class="list shibie">长按二维码关注</dl>
        <button type="button" class="button zdl">知道了</button>
    </div>
</div>

<!--弹出框—兑换成功-->
    <div class="hint-box" id="cardSuccess">
        <div class="hint cardSuccessBox">
		   <a class="close" href="javascript:void(0)"  id='successCancel'></a>
		   <div class="title">
            兑换成功
            </div>
			<a href="javascript:void(0);" class="button" id="goCard">查看我的卡包</a>
            </div>
        </div>
    </div>
<{include file="signBody.html"}>
<script>
    fixUserHead();
    var id="<{$obj.id}>";
    var offs=$('#fixed').offset();
    $(document).ready(function($){
        $(window).scroll(function(){
            scrollLis();
        });
        //倒计时函数
        timeout();

        function timeout(){
            var $point_timeer = $('#exchange-time');
            var time = parseInt($point_timeer.data("time"));
             $point_timeer.data("time",--time);
             if(time>=0){
                 setTimeout(function (){timeout();},1000);
                 output_time(time,$point_timeer);
             }else{
                 //秒杀绑定的ajax事件
                 $('#exchange-time').html('');
                 $('#exchange-btn').click(clickExchange).removeClass("yjs_2").addClass("yjs_1"); //移除disabled属性

             }
        }
        function output_time (time,obj) {
             var hour = Math.floor(time/60/60);
             var minute = Math.floor((time/60)%60);
             var scond = Math.floor(time%60);
             if(hour<10){
                 hour = '0' + hour;
             }
             if(minute<10){
                 minute = '0' + minute;
             }
             if(scond<10){
                 scond = '0' + scond;
             }
             $(obj).html("距离开抢&nbsp;&nbsp;&nbsp;"+hour+":"+minute+":"+scond);
        }
    });


    function refreshVal(data){
        $("#stock").html(data.stock);
        $("#quota").html(parseInt($("#quota").text())-1);

        if(typeof data.ext=='undefined'){
            return;
        }
        if(typeof data.ext.point!='undefined'){
            $('#nowPoint').text(data.ext.point);
        }
    }





    function clickExchange(){
        <{if !$userinfo}>
            location.href="<{U('User/login')}>";
            return;
        <{/if}>
            confirmOk();
    }

    $('#confirmCancel').click(function(e){
        $('#exchangeConfirm').hide();
    });

    $('#successCancel').click(function(){
        $('#cardSuccess').hide();
    });

    $('#goCard').click(function(){
        location.href="<{U('Card/cardList')}>";
    });

    //兑换绑定的onclick事件
//    $('#confirmOk').click(function(event){

    doing=false;
    function confirmOk(){
        $('#exchangeConfirm').hide();
        //需要发货
        const DELIVERY_SEND = <{$DELIVERY_SEND}>;
        //卡券
        const DELIVERY_CARD = <{$DELIVERY_CARD}>;



        var type        = $('#exchange-btn').data('type');
        var restTime    = $('#exchange-btn').data('time');
        if(restTime > 0)
        {
            layer.msg('活动还没开始');
        }else{
                $.ajax({
                    url:"<{U('PointMall/validateExchange')}>",
                    dataType:"json",
                    data:{"id":id},
                    type:"GET",
                    success:function(data){
                        console.log(data);
                        if(data.status == 0){
                            if(type == DELIVERY_SEND){
//                                $("#hint-send").css({"display":"block"});
//                                $('#send-title').html("");
                                window.location.href = "<{U('PointMall/exchange_deliverWay')}>&id=<{$obj.id}>";
                            }else if(type == DELIVERY_CARD){
                                if(doing){
                                    layer.msg("请求正在处理中，请等待。<br />若长时间无反应请刷新页面")
                                    return;
                                }
                                doing=true;
                                $.ajax({
                                    url:"<{U('PointMall/cardExchange')}>",
                                    dataType:"json",
                                    data:{"id":id},
                                    type:"GET",
                                    success:function(data){
                                        doing=false;
                                        if(data.status == 0){
                                            refreshVal(data);
                                            if(typeof data.orderStatus!='undefined' && data.orderStatus==3){
                                                window.location.href=data.jumpUrl;
                                            }else{

                                                if(data.isWeixinCard==1) {
                                                    layer.msg('正在向您发送微信卡券，请等待');
                                                    wx.addCard({
                                                        cardList: [{
                                                            cardId: data.wxCardID,
                                                            cardExt: data.cardExt
                                                        }], // 需要添加的卡券列表
                                                        success: function (res) {
                                                        },
                                                        cancel: function (res) {
                                                        }
                                                    });
                                                }else{
                                                    $('#cardSuccess').show();
                                                }
                                            }
                                        }else{
                                            layer.msg(data.msg);
                                        }
                                    },
                                });
                            }                      
                        }
                        else{
                            if(data.status==2){
                                $('#mustFollow').show();
                            }else{
                                layer.msg(data.msg);
                            }
                        }
                    },

                });
            }
        }
    //需要发货的弹出窗的ajax事件
    $('#send-btn-exchange').click(function(event){
        if(doing){
            layer.msg("请求正在处理，请稍候。<br />若长时间无反应，请刷新本页面")
            return;
        }
        doing=true;
        var phone = $('#send-phone').val();
        var name = $('#send-name').val();
        var address = $('#send-address').val();
        $.ajax({
            url:"<{U('PointMall/doExchange')}>",
            dataType:"json",
            data:{"id":id,"realname":name,"address":address,"phone":phone},
            type:"POST",  
            success:function(data){
                doing=false;
                if (data.status==0) {
                    if(typeof data.orderStatus!='undefined' && data.orderStatus==3){
                        window.location.href=data.jumpUrl;
                    }else{
                        $("#hint-send").css({"display":"none"});
                        layer.msg(data.msg);
                        refreshVal(data);
                    }
                }else{
                    layer.msg(data.msg);
                }
            },      
            error:function(data){
                layer.msg('异常');
            }
        });
    });
    $('#mustFollow .zdl').click(function(){$('#mustFollow').hide();});
</script>

</body>
</html>

